package com.kevinkk.tree;

/**
 * 给你一个二叉树的根节点 root ， 检查它是否轴对称。
 * 前序遍历，递归解决
 */

public class SymmetricTree {
    class Solution {
        public boolean isSymmetric(TreeNode root) {
            if (root == null) return true;
            return check(root.left, root.right);
        }

        private boolean check(TreeNode left, TreeNode right) {
            if (left == null && right == null) return true;
            if (left == null && right != null) return false;
            if (left != null && right == null) return false;
            if (left.val != right.val) return false;

            boolean out = check(left.left, right.right);
            boolean in = check(left.right, right.left);
            return out && in;
        }
    }
}
